﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinformTest_Com
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();

        }
        private int id;
       

        public Form2( int id,string name, int age, string native)
        {
            InitializeComponent();

            this.id = id;
            textBox1.Text = name;
            textBox2.Text = age.ToString();
            textBox3.Text = native;

        }

       

       
        private void button2_Click(object sender, EventArgs e)
        {


            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var name = textBox1.Text;
            var age = textBox2.Text;
            var native = textBox3.Text;
            //更新
            if (this.id > 0)
            {
                var sql = string.Format(" update employee set employeename='{0}',employeeage'{1}',employeenative'{2}' =where employeeid='{3}'", name, age, native, this.id);

                Class1.AddOrUpdata(sql);

                MessageBox.Show("更新成功", "提示");

            }//添加
            else
            {
                var sql = string.Format("insert into  employee (employeename,employeeage,employeenative) values('{0}','{1}','{2}'", name, age, native);

                Class1.AddOrUpdata(sql);

                MessageBox.Show("添加成功", "提示");

            }
            this.Close();

            
        }
       

      private void Form2_Load(object sender, EventArgs e)
       {

       }
    }
}
